Add max time to position filter.
authorrobertl <robertl>
Thu, 26 Jun 2008 20:28:13 +0000 (20:28 +0000)
committerrobertl <robertl>
Thu, 26 Jun 2008 20:28:13 +0000 (20:28 +0000)
jeeps/gpslibusb.c
position.c
xmldoc/filters/options/position-time.xml [new file with mode: 0644]

index a629e4bf9f4887a89a9cf1f5f0528886787729ee..20b5313818bb65c9019ee16009ba5f557dee17fe 100644 (file)
@@ -325,7 +325,7 @@ int garmin_usb_scan(libusb_unit_data *lud, int req_unit_number)
                 * that is wants to read and write GPX files on a 
                 * mounted drive.  Try that now.
                 */
-               gdx = gdx_find_file(".", NULL);
+               gdx = gdx_find_file(".");
                if (gdx) return 1;
                /* Plan C. */
                fatal("Found no Garmin USB devices.\n");
index 42247d2496066fa46f61b1a9bc6be0a4363389f7..cc05272525209d43acab24f940f40994c42d8946 100644 (file)
 static route_head *cur_rte = NULL;
 
 static double pos_dist;
+static double max_diff_time;
 static char *distopt = NULL;
+static char *timeopt = NULL;
 static char *purge_duplicates = NULL;
+static int check_time;
 
 typedef struct {
        double distance;
@@ -45,6 +48,8 @@ arglist_t position_args[] = {
        {"all", &purge_duplicates, 
                "Suppress all points close to other points", 
                NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, 
+       {"time", &timeopt, "Maximum time in seconds beetween two points",
+               NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED, ARG_NOMINMAX },
        ARG_TERMINATOR
 };
 
@@ -66,7 +71,7 @@ position_runqueue(queue *q, int nelems, int qtype)
        queue * elem, * tmp;
        waypoint ** comp;
        int * qlist;
-       double dist;
+       double dist, diff_time;
        int i = 0, j, anyitem;
 
        comp = (waypoint **) xcalloc(nelems, sizeof(*comp));
@@ -91,8 +96,12 @@ position_runqueue(queue *q, int nelems, int qtype)
                
                                                /* convert radians to integer feet */
                                        dist = (int)(5280*radtomiles(dist));
-                                               
+                                       diff_time = fabs( waypt_time(comp[i]) - waypt_time(comp[j]) );
+                                       
                                        if (dist <= pos_dist) {
+                                               if(check_time && diff_time >= max_diff_time)
+                                                       continue;
+                                               
                                                qlist[j] = 1;
                                                switch (qtype) {
                                                        case wptdata:
@@ -177,6 +186,8 @@ position_init(const char *args) {
        char *fm;
 
        pos_dist = 0;
+       max_diff_time = 0;
+       check_time = 0;
 
        if (distopt) {
                pos_dist = strtod(distopt, &fm);
@@ -186,6 +197,11 @@ position_init(const char *args) {
                         pos_dist *= 3.2802;
                }
        }
+
+       if (timeopt) {
+               check_time = 1;
+               max_diff_time = strtod(timeopt, &fm);
+       }
 }
 
 void
diff --git a/xmldoc/filters/options/position-time.xml b/xmldoc/filters/options/position-time.xml
new file mode 100644 (file)
index 0000000..b12bee7
--- /dev/null
@@ -0,0 +1,9 @@
+<para>
+  Specifies the maximum time in seconds between any two points. If the 
+  time difference is larger than what's specified here, the points will 
+  not be discarded.
+</para>
+<para>
+  This is useful if you have multiple tracks of the same course and you'd
+  like the filter to consider the tracks the same.
+</para>